﻿@using PagedList
@model PagedList.IPagedList<TaoNiuOA.Models.Task>
@{
    ViewBag.Title = "任务管理";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}
<script type="text/javascript">
    function showLevel(obj) {
        switch (obj) {
            case 0:
                document.write("低");
                break;
            case 1:
                document.write("普通");
                break;
            case 2:
                document.write("高");
                break;
            default:
                document.write("紧急");
        }
    }

    function showStatus(obj) {
        switch (obj) {
            case 0:
                document.write("未被领取");
                break;
            case 1:
                document.write("已被领取");
                break;
            case 2:
                document.write("执行中");
                break;
            default:
                document.write("已完成");
        }
    }
</script>
<fieldset>
    <legend><a href="myTask">我和任务</a> | 桃牛任务</legend>
    <div>
        <ul>
            <li><a href="?mod=all">所有任务</a></li>
            <li><a href="?mod=notTake">未领取的</a></li>
            <li><a href="?mod=take">已领取的</a></li>
            <li><a href="?mod=executing">执行中的</a></li>
            <li><a href="?mod=finish">已完成的</a></li>
        </ul>
    </div>
    <table>
        <tr>
            <th>
                名称
            </th>
            <th>
                类型
            </th>
            <th>
                绩效
            </th>
            <th>
                任务期限
            </th>
            <th>
                级别
            </th>
            <th>
                进度
            </th>
            <th>
                开始时间
            </th>
            <th>
                已持续天数
            </th>
            <th>
                状态
            </th>
            <th>
                最后更新
            </th>
            <th>
                负责人
            </th>
            <th>
                操作
            </th>
        </tr>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.Name)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.GetTaskType().TypeName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Point)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.ProjectLast)
                </td>
                <td>
                    <script>showLevel(@item.Level)</script>
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Process)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.StartTime)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.LastDays)
                </td>
                <td>
                    <script>showStatus(@item.Status)</script>
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.LastUpdate)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.GetUser().GetUserInfo().Name)
                </td>
                <td>
                    @Html.ActionLink("详细", "TaskDetails", new { id = item.TaskID }) | <a href="javascript:void(0);" onclick="takeTask(@item.TaskID)" >
                        领取任务</a>
                </td>
            </tr>
        }
    </table>
    <div style="width: auto; height: 30px; margin-top: 20px; text-align: center;">
        @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)
        / @Model.PageCount
        &nbsp;
        @if (Model.HasPreviousPage)
        {
            @Html.ActionLink("首页", "TaskList", new { mod = ViewData["mod"], page = 1, currentFilter = ViewBag.CurrentFilter })
            @Html.Raw("&nbsp;");
            @Html.ActionLink(" 上一页", "TaskList", new { mod = ViewData["mod"], page = Model.PageNumber - 1, currentFilter = ViewBag.CurrentFilter })
        }
        else
        {
            @Html.Raw("首页&nbsp;&nbsp;上一页")
        }
        &nbsp;
        @if (Model.HasNextPage)
        {
            @Html.ActionLink("下一页 ", "TaskList", new { mod = ViewData["mod"], page = Model.PageNumber + 1, currentFilter = ViewBag.CurrentFilter })
            @Html.Raw("&nbsp;");
            @Html.ActionLink("尾页", "TaskList", new { mod = ViewData["mod"], page = Model.PageCount, currentFilter = ViewBag.CurrentFilter })
        }
        else
        {
            @Html.Raw("下一页&nbsp;&nbsp;尾页")
        }
    </div>
</fieldset>
<script src="../../Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
    function takeTask(obj) {
        if (confirm("您确认要领取该任务吗?")) {
            $.post("takeTask?id=" + obj,
            function (data) {
                alert(data);
                if (data != "该任务已经被领取")
                    window.location.reload();
            });
        }
    }
</script>
